package wsi.gui.detector;

import java.awt.Dimension;
import java.awt.event.KeyEvent;

import org.rygh.gui.swing.button.SButton;
import org.rygh.gui.swing.button.SCloseButton;
import org.rygh.gui.swing.component.STextArea;
import org.rygh.gui.swing.field.SIntegerField;
import org.rygh.gui.swing.field.SStringField;
import org.rygh.gui.swing.presenter.SwingPresenter;
import org.rygh.gui.swing.table.STableView;
import org.rygh.gui.swing.window.SwingWindow;

@SuppressWarnings("serial")
public class DetectorWindow extends SwingWindow implements DetectorPresenter.Display {

	private final DetectorView view = new DetectorView();
	private final SwingPresenter presenter;

	public DetectorWindow(SwingPresenter presenter) {
		super("Select Input Values");

		this.presenter = presenter;

		layoutComponents();
		center();
	}

	@Override
	public SStringField getFunctionField() {
		return view.getFunctionField();
	}

	@Override
	public SIntegerField getLimitField() {
		return view.getLimitField();
	}

	@Override
	public STextArea getQueryArea() {
		return view.getQueryArea();
	}

	@Override
	public STableView getTable() {
		return view.getTable();
	}

	private void layoutComponents() {
		view.setPreferredSize(new Dimension(540, 400));
		getTable().setSortable();

		addButton(new SCloseButton(this));
		addButton(new SButton("View Inputs", KeyEvent.VK_I, presenter,
				"viewInputs"));
		addButton(new SButton("Detect", KeyEvent.VK_D, presenter, "detect"));
		addButton(new SButton("Function", KeyEvent.VK_F, presenter,
				"selectFunction"));

		addCenterView(view);

		pack();
	}
}
